home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-11-19 | 1.4 KB | 106 lines | [TEXT/MPCC] |
- // InPoint.cpp
-
- #include "InPoint.h"
-
- #define TIMEOUT 2000
-
-
-
- InPoint::InPoint(
- const char *protocol,
- const char *address,
- short port)
- {
- OSErr err = Open(protocol);
- if (err)
- throw err;
-
- err = Bind(port);
- if (err)
- throw err;
-
- // make it asynchronous and set up to receive
-
- OTSetAsynchronous(fEndpoint);
- OTInstallNotifier(fEndpoint, &Notifier, this);
- }
-
-
- InPoint::~InPoint()
- {
- }
-
-
-
- pascal void
- InPoint::Notifier(
- void* contextPtr,
- OTEventCode code,
- OTResult result,
- void* cookie)
-
- // *** Called at deferred task time. ***
-
- {
- InPoint* thisPoint = (InPoint*) contextPtr;
- thisPoint->HandleNotify(code, result, cookie);
- }
-
-
- void
- InPoint::HandleNotify(
- OTEventCode code,
- OTResult result,
- void* cookie)
-
- // *** Called at deferred task time. ***
-
- {
- switch (code) {
- case T_DATA:
- GetData();
- break;
-
-
-
- }
- }
-
-
- void
- InPoint::GetData()
-
- {
- unsigned char foo[256];
- while (1) {
- TUnitData uData = {
- { 256, 0, foo },
- { 0, 0, NULL },
- { sizeof(packetBuffer), 0, (UInt8*) &fPacket },
- };
- OTFlags flags;
-
- OSStatus theErr = OTRcvUData(fEndpoint, &uData, &flags);
- if (theErr == kOTNoDataErr)
- break;
- if (theErr != noErr) {
- Str15 s;
- NumToString(theErr, s);
- DebugStr(s);
- continue;
- }
-
- DoSomethingWithTheData(&fPacket, uData.udata.len);
- }
- }
-
-
- void
- InPoint::DoSomethingWithTheData(
- void *data,
- long len)
- {
- // do nothing in this class - please override
- }
-
-